<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <style>
        #pic {
            display: none;
        }
    </style>
</head>

<body>
    <canvas id="canvas" width="800" height="500"></canvas>
    <img src="img/atan.png" alt="" id="pic">
    <script>
        window.onload = function () {
            var canvas = document.getElementById('canvas'),
                context = canvas.getContext('2d'),
                //通过js加载图片
                //     img = new Image()
                // img.src = 'img/atan.png'
                // img.onload = function () {
                //     context.drawImage(img, 0, 0)
                // }

                //通过dom元素加载图片
                img = document.getElementById('pic')
            context.drawImage(img, 0, 0)
        }
    </script>
</body>

</html>